<template>
	<view class="container">
		<!-- <button @click="test">测试</button> -->
		<Zxing @success='qrcodeSucess' @error="qrcodeError" :continue="false">
			<template v-slot:error>
				<view>摄像头启动失败</view>
			</template>
		</Zxing>
	</view>
</template>

<script>
	import Zxing from './Zxing.vue' //引入


	export default {
		components: {
			Zxing //注册
		},
		data() {
			return {

			}
		},
		name: 'scanQrCode',
		methods: {
			test() {
				this.$emit('qrCode', '1857282511743938560')
			},
			qrcodeSucess(data) { //摄像头扫码成功后返回
				console.log('摄像头扫码成功 =>', data)
				this.$emit('qrCode', data)
				// uni.showModal({
				// 	title: '成功',
				// 	content: data,
				// 	success: () => {}
				// })
			},
			qrcodeError(err) { //摄像头扫码失败返回
				console.log('err', err)
				uni.showModal({
					title: '摄像头授权失败',
					content: '摄像头授权失败，请检测当前浏览器是否有摄像头权限。',
					success: () => {
						uni.navigateBack({}) //返回到上一页
					}
				})
			}

		},
		onLoad() {

		}
	}
</script>

<style scoped lang="scss">
	.container {
		height: 100%;
	}
</style>